package com.example.ujsfish.activity;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;

import com.example.ujsfish.R;
import com.example.ujsfish.coord.CoordinateXY;
import com.example.ujsfish.utils.AppNetService;
import com.example.ujsfish.model.MyPoint;
import com.example.ujsfish.model.PlanPoint;
import com.example.ujsfish.model.PlanPointBody;
import com.example.ujsfish.model.manual.ManualControlData;
import com.example.ujsfish.model.monitor.Data;
import com.example.ujsfish.model.monitor.JsonRootBean;
import com.example.ujsfish.model.ship.PoolName;
import com.example.ujsfish.utils.DeviceName;
import com.example.ujsfish.utils.RetrofitManager;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;

public class AddPathPoint extends AppCompatActivity implements AdapterView.OnItemSelectedListener {

    private static final String TAG = "AddPathPoint";
    RetrofitManager myRetrofitManager = RetrofitManager.getInstance();
    Retrofit myRetrofit = RetrofitManager.getRetrofit();
    AppNetService appNetService = myRetrofitManager.getApiService(AppNetService.class);



    private ManualControlData.ManualBody manualBody = ManualControlData.getManualBody();

    String id;


    private Button btn_addNewPoint;
    private Button btn_getPointPosition;
    private Button btn_submitAdd;
    private Button btn_updateAllPoint;
    private Button btn_stop3;
    private Button btn_setValue;
    private Button btn_figureValue;
    private Button btn_commit;

    private CheckBox check_isLocked;

    private ImageView moveForward;
    private ImageView moveBack;
    private ImageView moveLeft;
    private ImageView moveRight;

    private EditText text_point_X;
    private EditText text_point_Y;
    private EditText text_shipSpeed;
    private EditText text_feedPwm;
    private EditText text_feedValue;
    private EditText text_path_id;

    private TextView text_speed;

    private Spinner spinner_poolName;
    private Spinner spinner_pointOrder;

    //对应序号的投饵占比
    private List<String> myRatio = new ArrayList<>();
    //对应序号投饵占比的锁定状态，true为锁定，false为系统生成
    private List<Boolean> myPointState = new ArrayList<>();

    //计算两点间的距离用到的两个临时变量
    private List<MyPoint> myPointList = new ArrayList<>();
    private List<String> myDistance = new ArrayList<>();

    //当此标志位为true时，spinner将用于展示已生成的地图数据，修改投饵占比
    private  boolean spinnerModel = false;

    List<String> name_list = new ArrayList<>();
    String name; //存放池塘编号的变量
    List<String> order_list = new ArrayList<>();
    String order;//存放节点序号的变量
    int count = 0;
    private String originLng;
    private String originLat;

    PlanPoint planPoint;  //临时存放轨迹点

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.add_path_point_activity);

        SharedPreferences preferences = getSharedPreferences("data",MODE_PRIVATE);
        String userName = preferences.getString("userName", "");

//        MyApplication app = (MyApplication) getApplication();
//        app.getPlanPoint().clear();
//        planPoint = app.getPlanPoint();
        planPoint = new PlanPoint();

        initPoolNameSpinner(userName);
        id = DeviceName.getDeviceInstance().getDeviceId().get(0);
        initView();
        moveControl();
        initOrderSpinner();

//        if(check_isLocked.isChecked()){
//            text_feedValue.setEnabled(true);
//        }else if (!check_isLocked.isChecked()){
//            text_feedValue.setEnabled(false);
//        }

        //再展示与修改模式下才开放以下功能
//        if (spinnerModel){
//            //使修改按键使能
//            btn_commit.setEnabled(true);
//            check_isLocked.setClickable(false);
//        }

        //向本地提交修改后的投饵占比数据
        btn_commit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //planPoint.getPlanPointBodyList().get(Integer.parseInt(order)).setBait_ratio(text_feedValue.toString());
                //更新myRatio和myPointState,再使用setBaitRatio函数更新myPercent
                myRatio.set(Integer.parseInt(order) - 1,text_feedValue.getText().toString());
                myPointState.set(Integer.parseInt(order) - 1,check_isLocked.isChecked());
            }
        });

        //根据已有的
        btn_figureValue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //判断节点数大于0
                if (planPoint.getPlanPointBodyList().size() == count && count != 0){
                    setBaitRatio();
                }
            }
        });

        btn_setValue.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Log.d(TAG, "size is:" +planPoint.getPlanPointBodyList().size() + "\t" + "count is:" + count);

                //判断节点数大于0
                if (planPoint.getPlanPointBodyList().size() == count && count != 0){
                    setBaitRatio();
                    //将模式切换到展示，修改数据模式
                    spinnerModel = true;
                    btn_commit.setEnabled(true);
                }else{
                    Toast.makeText(getApplication(),"请先添加轨迹点",Toast.LENGTH_SHORT).show();
                }


            }
        });

        check_isLocked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (check_isLocked.isChecked()) {
                    text_feedValue.setEnabled(false);
                } else if (!check_isLocked.isChecked()) {
                    text_feedValue.setEnabled(true);
                }
            }
        });

        btn_addNewPoint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                //使修改按钮不可用
                btn_commit.setEnabled(false);
                //将锁定check按钮复位
                check_isLocked.setChecked(false);


                //将节点序号加一
                count++;
                if (count >= 10){
                    order_list.add(String.valueOf(count));
                }else {
                    order_list.add( "0" + count);
                }
                System.out.println("order size is " + order_list.size());
                initOrderSpinner();
                //将最新的节点序号设置为默认值
                spinner_pointOrder.setSelection(count - 1,true);

                //将其他数据清除
                text_point_X.setText("");
                text_point_Y.setText("");
                text_shipSpeed.setText("1.0");
                text_feedPwm.setText("80");
                text_feedValue.setText("00");

            }
        });

        //获取实时坐标
        btn_getPointPosition.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Call<JsonRootBean> call1 = appNetService.postMonitor(id);
                call1.enqueue(new Callback<JsonRootBean>() {
                    @Override
                    public void onResponse(Call<JsonRootBean> call, Response<JsonRootBean> response) {
                        System.out.println(response.toString());

                        JsonRootBean jsonRootBean = response.body();
                        List<Data> monitData = jsonRootBean.getData();
                        if(monitData != null && monitData.size() > 0) {
                            Data lastData = monitData.get(0);
//                            originLng = lastData.getOrigin_longitude();
//                            originLat = lastData.getOrigin_latitude();

                            text_point_X.setText(lastData.getX_coordinate());
                            text_point_Y.setText(lastData.getY_coordinate());
                            originLng = lastData.getOrigin_longitude();
                            originLat = lastData.getOrigin_latitude();

                        }else {
                            Toast.makeText(getApplication(),"无法获取实时坐标，请确保船只已上线",Toast.LENGTH_LONG).show();
                        }


                    }

                    @Override
                    public void onFailure(Call<JsonRootBean> call, Throwable t) {
                        Log.d(TAG, "onFailure: " + t.toString());
                    }
                });
            }
        });

        //将确认的点存入集合
        btn_submitAdd.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                String id = text_path_id.getText().toString();
                String X = text_point_X.getText().toString();
                String Y = text_point_Y.getText().toString();
//
//                if (X.equals("") || Y.equals("")) {
//                    Toast.makeText(getApplicationContext(),"请输入正确坐标点",Toast.LENGTH_SHORT).show();
//                    return;
//                }
//                if (id.equals("") ) {
//                    Toast.makeText(getApplicationContext(),"请输入此路径的名称",Toast.LENGTH_SHORT).show();
//                    return;
//                }

                Log.d(TAG, "id:" + id + "\t" + "X:" + X + "\t" + "Y:" +Y );
                if(!id.equals("") && !X.equals("") && !Y.equals("")){

                    //重复点击了添加轨迹点
                    if (planPoint.isHasPoint(Integer.parseInt(order))) {
                        Toast.makeText(getApplicationContext(),"请勿重复添加相同的轨迹点",Toast.LENGTH_SHORT).show();
                        return;
                    }

                    //直接输入经纬度需要将其转换为平面坐标
                    if (!machCoordinate(X) | !machCoordinate(Y)) {
                        CoordinateXY coordinateXY = new CoordinateXY(originLng,originLat);
                        coordinateXY.getCoordinate(Double.parseDouble(X), Double.parseDouble(Y));
                        X = coordinateXY.getMovetoplaneENx();
                        Y = coordinateXY.getMovetoplaneENy();
                    }


                    planPoint.setPool_id(name);
                    planPoint.setPath_id(text_path_id.getText().toString());

                    //将锁定状态存入集合
                    myPointState.add(check_isLocked.isChecked());
                    myRatio.add(text_feedValue.getText().toString());

                    //将所有点转化为坐标点
                    //getAllPoints(text_point_X.getText().toString(),text_point_Y.getText().toString());
                    getAllPoints(X,Y);


                    //PlanPointBody planPointBody = new PlanPointBody(String.valueOf(order),X,Y,text_shipSpeed.getText().toString(),text_feedPwm.getText().toString(),text_feedValue.getText().toString());
                    PlanPointBody planPointBody = new PlanPointBody(String.valueOf(order),X,Y,getLimitSpeed(text_shipSpeed),text_feedPwm.getText().toString(),text_feedValue.getText().toString());
                    System.out.println(planPoint.getPlanPointBodyList() == null);



                    planPoint.getPlanPointBodyList().add(planPointBody);
                    Log.d(TAG, "planPointBodyList: " + planPoint.getPlanPointBodyList().toString());

                }else{
                    AlertDialog.Builder builder = new AlertDialog.Builder(AddPathPoint.this);
                    builder.setTitle("提示：");
                    builder.setMessage("路径名称或坐标点未添加");
                    builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            dialog.dismiss();
                        }
                    });
                    builder.show();
                }


            }

        });

        //将存放轨迹点的集合上传到服务器
        btn_updateAllPoint.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog.Builder builder = new AlertDialog.Builder(AddPathPoint.this);
                builder.setTitle("提示：");
                builder.setMessage("确认上传轨迹点？");
                builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                        planPoint.setUserName(userName);
                        Call<ResponseBody> call = appNetService.postAddPath(planPoint.getPool_id(), planPoint.getPath_id(),planPoint.getUserName(), planPoint.getPlanPointBodyList());
                        call.enqueue(new Callback<ResponseBody>() {
                            @Override
                            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                                clearData();
                                System.out.println(response.message().toString());
                                Toast.makeText(getApplicationContext(),"上传成功",Toast.LENGTH_LONG).show();
                            }

                            @Override
                            public void onFailure(Call<ResponseBody> call, Throwable t) {
                                t.printStackTrace();
                            }
                        });

                        System.out.println("集合为：" + planPoint.toString());
                    }
                });
                builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
                builder.show();

//                spinnerModel = false;
//                count = 0;
//                app.getPlanPoint().setUserName(userName);
//                Call<ResponseBody> call = appNetService.postAddPath(app.getPlanPoint().getPool_id(), app.getPlanPoint().getPath_id(),app.getPlanPoint().getUserName(), app.getPlanPoint().getPlanPointBodyList());
//                call.enqueue(new Callback<ResponseBody>() {
//                    @Override
//                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
//                        System.out.println(response.body());
//                    }
//
//                    @Override
//                    public void onFailure(Call<ResponseBody> call, Throwable t) {
//                        t.printStackTrace();
//                    }
//                });
//
//                System.out.println("集合为：" + app.getPlanPoint().toString());

            }


        });



    }

    /**
     * 将船速限制在0.6-1.0之间
     * @param text_shipSpeed
     * @return
     */
    private String getLimitSpeed(EditText text_shipSpeed) {
        Log.d(TAG, "getLimitSpeed: " + String.valueOf(text_shipSpeed.getText()));
        Float speed = Float.valueOf(String.valueOf(text_shipSpeed.getText()));
        if (speed < 0.6f) speed = 0.6f;
        if (speed > 1.0f) speed = 1.0f;
        return String.valueOf(speed);
    }

    private void clearData() {
        planPoint.clear();
        spinnerModel = false;
        count = 0;
    }

    private boolean machCoordinate(String pointString) {
        if (pointString.trim().length() != 6) {
            return false;
        }
        String pattern = "[SWEN]\\d\\d\\d\\.\\d";
        Pattern r = Pattern.compile(pattern);
        Matcher m = r.matcher(pointString);
        return m.matches();
    }


    private void setBaitRatio() {

        float  restProportion = 100f;
        Float sumDistance = 0f;
        Log.d(TAG, "myPointList.size() is " + myPointList.size());
        Float Distance [] = new Float[myPointList.size()];
        Float myPercent [] = new Float[myPointList.size()];


        //List<PlanPointBody> planPointBodyList = app.getPlanPoint().getPlanPointBodyList();

        //更新锁定的投饵占比，
        //计算未锁定到其下一个点的距离
        for (int i = 0; i < myPointList.size() - 1; i++) {
            if(myPointState.get(i)){//锁定占比
                Log.d(TAG, "myPointState: " + myPointState.get(i));
                restProportion -= Float.parseFloat(myRatio.get(i));
                Log.d(TAG, "restProportion: " + restProportion);
            }else if (!myPointState.get(i)){ //未锁定占比自动生成
                Log.d(TAG, "myPointState: " + myPointState.get(i));
                Distance [i] = getDistance(myPointList.get(i),myPointList.get(i + 1));
                sumDistance += Distance[i];
                Log.d(TAG, "sumDistance: " + sumDistance);
            }
        }

        for (int i = 0; i < myPointList.size() - 1; i++){
            if(myPointState.get(i)){
                myPercent[i] = Float.valueOf(myRatio.get(i));
            }else if (!myPointState.get(i)){
                myPercent[i] = Distance[i] / sumDistance * restProportion;
            }
            Log.d(TAG, "第" + i +"个节点投饵占比:" + Arrays.toString(myPercent));
        }


        //装载计算好的投饵量
//        for (int i = 0; i < planPointBodyList.size() - 1; i++) {
//
//            planPointBodyList.get(i).setBait_ratio(String.valueOf(Math.round(myPercent[i])));
//            Log.d(TAG, "Bait_ratio:" + myPercent[i]);
//        }

        for (int i = 0; i < myPercent.length - 1; i++) {
            int round = Math.round(myPercent[i]);
            if (round < 10) {
                planPoint.getPlanPointBodyList().get(i).setBait_ratio("0" + round);
            }else {
                planPoint.getPlanPointBodyList().get(i).setBait_ratio(String.valueOf(round));
            }

        }
        planPoint.getPlanPointBodyList().get(myPercent.length -1).setBait_ratio("00");
        //planPointBodyList.get(planPointBodyList.size() - 1).setBait_ratio("00.0");


        Log.d(TAG, "setBaitRatio: " + planPoint.getPlanPointBodyList().toString());
    }

    //计算两点之间距离
    private float getDistance(MyPoint myPoint1, MyPoint myPoint2) {
        return (float) Math.sqrt(Math.pow((myPoint1.getCurrentX()-myPoint2.getCurrentX()),2) + Math.pow((myPoint1.getCurrentY()-myPoint2.getCurrentY()),2));

    }


    //将点转化为MyPoint对象
    private void getAllPoints(String X, String Y) {
        MyPoint myPoint = new MyPoint(X,Y);
        myPointList.add(myPoint);
    }

    private void initPoolNameSpinner(String userName){
        spinner_poolName = findViewById(R.id.spinner_poolName);
        Call<PoolName> poolNameCall = appNetService.postFindPoolNameBU(userName);
        poolNameCall.enqueue(new Callback<PoolName>() {
            @Override
            public void onResponse(Call<PoolName> call, Response<PoolName> response) {
                PoolName poolName = response.body();
                List<String> pathName_list = new ArrayList<>();
                //防止返回的数据中有空数据
                for (String data :
                        poolName.getData()) {
                    if (data != null){
                        pathName_list.add(data);
                    }
                }
                initPoolSpinner(pathName_list, spinner_poolName);
            }

            @Override
            public void onFailure(Call<PoolName> call, Throwable t) {

            }
        });


    }

    private void initPoolSpinner(List<String> name_list, Spinner spinner_poolName) {
        ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, name_list);
        //设置样式
        arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        //加载适配器
        spinner_poolName.setAdapter(arrayAdapter);
        //为Spinner设置选中事件监听器
        spinner_poolName.setOnItemSelectedListener(AddPathPoint.this);
    }

    private void initOrderSpinner() {
        spinner_pointOrder = findViewById(R.id.spinner_pointOrder);


//        for (int i = 0; i < DeviceName.getDeviceInstance().getDeviceId().size() -1; i++) {
//            name_list.add(DeviceName.getDeviceInstance().getDeviceId().get(i));
//        }


        initPoolSpinner(order_list, spinner_pointOrder);

    }

    private void moveControl() {
        manualBody.clear();
        //手动控制指令
        moveForward.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                manualBody.setLeftWheelAdd();
                manualBody.setRightWheelAdd();
                sendManualCm(id);
            }
        });

        moveBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                manualBody.setLeftWheelDelete();
                manualBody.setRightWheelDelete();
                sendManualCm(id);
            }
        });

        moveLeft.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                manualBody.setRightWheelAdd();
                sendManualCm(id);

            }
        });

        moveRight.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                manualBody.setLeftWheelAdd();
                sendManualCm(id);
            }
        });

        btn_stop3.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                manualBody.clear();
                Call<ResponseBody> call = appNetService.postStop(id);
                call.enqueue(new Callback<ResponseBody>() {
                    @Override
                    public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                        Log.d(TAG, "onResponse: " + response);
                        updateSpeed();

                    }

                    @Override
                    public void onFailure(Call<ResponseBody> call, Throwable t) {

                    }
                });

            }
        });

    }



    private void sendManualCm(String id) {
        manualBody.setDevice_name(id);
        Log.d(TAG, "sendManualCm: " + manualBody.toString());
        Call<ResponseBody> call = appNetService.postManualControl(manualBody);
        call.enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                Log.d(TAG, "onResponse: " + response);
                updateSpeed();
            }

            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {

            }
        });
    }

    //每当手动改变速度时，更新速度显示ui
    private void updateSpeed() {
        String left_wheel = manualBody.getLeft_wheel();
        String right_wheel = manualBody.getRight_wheel();
        text_speed.setText(String.format("%s ! %s", left_wheel, right_wheel));
    }

    private void initView() {
        moveForward = findViewById(R.id.btn_forward3);
        moveBack = findViewById(R.id.btn_back3);
        moveLeft = findViewById(R.id.btn_left3);
        moveRight = findViewById(R.id.btn_right3);

        btn_addNewPoint = findViewById(R.id.btn_addNewPoint);
        btn_getPointPosition = findViewById(R.id.btn_getPointPosition);
        btn_submitAdd = findViewById(R.id.btn_submitAdd);
        btn_updateAllPoint = findViewById(R.id.btn_updateAllPoint);
        btn_stop3 = findViewById(R.id.btn_stop3);
        btn_setValue = findViewById(R.id.btn_setValue);
        btn_figureValue = findViewById(R.id.btn_figureValue);
        btn_commit = findViewById(R.id.btn_commit);

        check_isLocked = findViewById(R.id.check_isLocked);

        text_point_X = findViewById(R.id.text_point_X);
        text_point_Y = findViewById(R.id.text_point_Y);
        text_shipSpeed = findViewById(R.id.text_shipSpeed);
        text_feedPwm = findViewById(R.id.text_feedPwm);
        text_feedValue = findViewById(R.id.text_feedValue);
        text_path_id = findViewById(R.id.text_pathName);

        text_speed = findViewById(R.id.text_speed1);

        Call<JsonRootBean> call1 = appNetService.postMonitor(id);
        call1.enqueue(new Callback<JsonRootBean>() {
            @Override
            public void onResponse(Call<JsonRootBean> call, Response<JsonRootBean> response) {
                System.out.println(response.toString());
                JsonRootBean jsonRootBean = response.body();
                List<Data> monitData = jsonRootBean.getData();
                if(monitData != null && monitData.size() > 0) {
                    Data lastData = monitData.get(0);
                    originLng = lastData.getOrigin_longitude();
                    originLat = lastData.getOrigin_latitude();
                }else {
                    Toast.makeText(getApplication(),"无法获取实时坐标，请确保船只已上线",Toast.LENGTH_LONG).show();
                }
            }

            @Override
            public void onFailure(Call<JsonRootBean> call, Throwable t) {
                Log.d(TAG, "onFailure: " + t.toString());
            }
        });
    }

    @Override
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
        String data = parent.getItemAtPosition(position).toString();
        System.out.println("data" + data);
        TextView tv1;
        TextView tv2;

        switch (parent.getId()){
            case R.id.spinner_poolName:
                name = data;

                tv1 = (TextView)view;
                //tv1.setTextColor(getResources().getColor(R.color.colorBlack));
                break;
            case R.id.spinner_pointOrder:
                order = data;
                tv2 = (TextView)view;
                Log.d(TAG, "model is " + spinnerModel);
                //在选择下拉框后，如果是展示与修改模式，将算好的占比与锁定状态填入对应控件。如果是锁定状态，则将占比文本框disEnabled
                if (spinnerModel){
                text_feedValue.setText(planPoint.getPlanPointBodyList().get(Integer.parseInt(data) - 1).getBait_ratio());
                check_isLocked.setChecked(myPointState.get(Integer.parseInt(data) - 1));
                if (myPointState.get(Integer.parseInt(order) - 1 )){
                    text_feedValue.setEnabled(false);
                }else if(!myPointState.get(Integer.parseInt(order) - 1)){
                    text_feedValue.setEnabled(true);
                }
            }
                //tv2.setTextColor(getResources().getColor(R.color.colorBlack));
                break;
            default:break;
        }

    }

    @Override
    public void onNothingSelected(AdapterView<?> parent) {

    }

}